Iterate through digital inputs

This example is for Wiring version 0027+. If you have a previous version, use the examples included with your software. If you see any errors or have comments, please let us know.

Conditionals.

Conditions are like questions. They allow a program to decide to take one action if the answer to a question is true or to do another action if the answer to the question is false. The questions asked within a program are always logical or relational statements. For example, if the variable 'i' is equal to zero then turn on a light.


int RED = 0;   // red LED on digital pin 0
int BLUE = 1;  // blue LED on digital pin 1

void setup() {
  pinMode(RED, OUTPUT);
  pinMode(BLUE, OUTPUT);
}

void loop() {
  for(int i=10; i<32000; i+=10) {
    // If 'i' divides by 37 with no remainder turn ON the blue LED
    // else turn ON the red LED
    if(i%37 == 0) {
      digitalWrite(RED, LOW);
      digitalWrite(BLUE, HIGH);
      delay(200);  // delay to visualize the LED change
    } 
    else {
      digitalWrite(RED, HIGH);
      digitalWrite(BLUE, LOW);
      delay(200);  // delay to visualize the LED change
    }
  }
}